package com.donfu.system.service.house.impl;

import java.util.*;

import com.donfu.system.mapper.house.HouseExclusiveserviceMapper;
import com.donfu.system.service.house.IHouseRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.donfu.system.mapper.house.HouseStoreMapper;
import com.donfu.system.domain.house.HouseStore;
import com.donfu.system.service.house.IHouseStoreService;

/**
 * 店铺信息Service业务层处理
 * 
 * @author donfu
 * @date 2021-12-01
 */
@Service
public class HouseStoreServiceImpl implements IHouseStoreService 
{
    @Autowired
    private HouseStoreMapper houseStoreMapper;

    @Autowired
    private HouseExclusiveserviceMapper houseExclusiveserviceMapper;

    /**
     * 查询店铺信息
     * 
     * @param id 店铺信息主键
     * @return 店铺信息
     */
    @Override
    public HouseStore selectHouseStoreById(Long id)
    {
        return houseStoreMapper.selectHouseStoreById(id);
    }

    /**
     * 查询店铺信息列表
     * 
     * @param houseStore 店铺信息
     * @return 店铺信息
     */
    @Override
    public List<HouseStore> selectHouseStoreList(HouseStore houseStore)
    {
        return houseStoreMapper.selectHouseStoreList(houseStore);
    }

    /**
     * 新增店铺信息
     * 
     * @param houseStore 店铺信息
     * @return 结果
     */
    @Override
    public int insertHouseStore(HouseStore houseStore)
    {
        houseStore.setCreateDate(new Date());
        return houseStoreMapper.insertHouseStore(houseStore);
    }

    /**
     * 修改店铺信息
     * 
     * @param houseStore 店铺信息
     * @return 结果
     */
    @Override
    public int updateHouseStore(HouseStore houseStore)
    {
        houseStore.setUpdateDate(new Date());
        return houseStoreMapper.updateHouseStore(houseStore);
    }

    /**
     * 批量删除店铺信息
     * 
     * @param ids 需要删除的店铺信息主键
     * @return 结果
     */
    @Override
    public int deleteHouseStoreByIds(Long[] ids)
    {
        int number=0;
        for(Long id:ids){
            int i = houseStoreMapper.deleteHouseStoreById(id);
            // 如果删除店铺信息成功，则需要删除我的导购中的相关店铺的数据
            if(i==1){
                number++;
                houseExclusiveserviceMapper.deleteHouseExclusiveserviceByStorId(id);
            }
        }
        return number;
    }

    /**
     * 删除店铺信息信息
     * 
     * @param id 店铺信息主键
     * @return 结果
     */
    @Override
    public int deleteHouseStoreById(Long id)
    {
        return houseStoreMapper.deleteHouseStoreById(id);
    }

    /**
     * 包含导购人数的查询
     * @param houseStore
     * @return
     */
    @Override
    public List<Map<String,Object>> selectHouseStoreListIncluding(HouseStore houseStore) {
        return houseStoreMapper.selectHouseStoreListIncluding(houseStore);
    }

    /**
     * 查询所有店铺所在的城市
     * @return
     */
    @Override
    public List<Map<String, String>> selectHouseStoreCityList() {
        return houseStoreMapper.selectHouseStoreCityList();
    }

    /**
     * 获取店铺总个数
     * @return
     */
    @Override
    public int selectHouseStoreCount(String cityId) {
        return houseStoreMapper.selectHouseStoreCount(cityId);
    }
}
